package com.itheima.zhuanhuan;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.itheima.domain.Student;
/*
HashMap存储学生对象
- 创建一个HashMap集合，键是学生对象(Student)，值是居住地 (String)。存储多个元素，并遍历。
- 要求保证键的唯一性：如果学生对象的成员变量值相同，我们就认为是同一个对象
注意:想要按照指定的排序规则进行排序 必须实现Comparable 接口或者手动写 比较器
 */
public class Test03 {

    public static void main(String[] args) {
        HashMap<Student, String> map = new HashMap<>();

        Student lu = new Student("鹿晗", 28);
        Student guan = new Student("关晓彤", 22);
        Student wu = new Student("吴亦凡", 27);
        Student cai = new Student("蔡徐坤", 28);
        Student cai2 = new Student("蔡徐坤", 28);
        map.put(lu,"太原市淖马村");
        map.put(guan,"太原市上兰村");
        map.put(wu,"太原市许西村");
        map.put(cai,"太原市大马村");
        map.put(cai2,"太原市大马村2");
        //第一种 keyset

        Set<Student> students = map.keySet();
        for (Student student : students) {
            String home = map.get(student);
            System.out.println(student+"===他家在"+home);
        }
        //第二种 entrySet
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student student = entry.getKey();
            String home = entry.getValue();
            System.out.println(
                    student+"========他家在"+home
            );

        }
    }
}
